require 'sketchup.rb'
require File.join(__FILE__, '../amtf_mixin.rb')
module AMTF
  unless file_loaded?(__FILE__)
    menu = UI.menu('Plugins')
    menu.add_item('amtf_su') {
      # self.主页
      AMTF::AMTF窗口.new
    }
    file_loaded(__FILE__)
  end
  class AMTF窗口 < UI::WebDialog
    include AMTF_mixin
    def initialize
      # Dialog parameters
      super "amtf", false, "amtf", 350, 600, 50, 100, true
      path = File.join(__dir__, '/amtf_su.html')
      set_file path
      navigation_buttons_enabled = false
      min_width = 50
      min_height = 50

      # Set the WebDialog's callback
      add_action_callback("hei") {|dialog, arg|
          puts arg
      }

      add_action_callback("你好么") {|dialog, arg|
          puts arg
      }
      add_action_callback("刷新amtf") {|dialog, arg|
        AMTF::reload
        # puts arg+" 完成！"
        Sketchup::set_status_text arg+" 完成！"
        # return arg+" 完成！"
      }
      add_action_callback("匹配尺寸") {|dialog, arg|
        Sketchup.active_model.select_tool AF匹配尺寸.new
      }
      add_action_callback("对齐") {|dialog, arg|
        # Sketchup.active_model.select_tool( AF对齐.new )
        Sketchup.active_model.select_tool AF对齐.new
      }
      add_action_callback("画柜子") {|dialog, arg|
        # p "hello"
        Sketchup.active_model.select_tool AF画柜子.new(arg+".skp")
      }
      add_action_callback("另存为排版模型") {|dialog, arg|
        AF另存排版.new().另存为排版模型
      }
      add_action_callback("删除指定图层") {|dialog, arg|
         Sketchup::set_status_text __method__.to_s()+" ing"
        AF另存排版.new().删除指定图层
      }
      add_action_callback("删除隐藏项目") {|dialog, arg|
        AF另存排版.new().删除隐藏项目
      }
      add_action_callback("删除or炸开无板字组件") {|dialog, arg|
        AF另存排版.new().删除or炸开无板字组件
      }
      add_action_callback("炸开所有子组件") {|dialog, arg|
        AF另存排版.new().炸开所有子组件
      }
      add_action_callback("组件改名") {|dialog, arg|
        AF另存排版.new().组件改名
      }
      add_action_callback("组件转群组") {|dialog, arg|
        AF另存排版.new().组件转群组
      }
      add_action_callback("一键排版预处理") {|dialog, arg|
        AF另存排版.new().一键排版预处理
      }
      add_action_callback("延伸背板") {|dialog, arg|
        AF另存排版.new().延伸背板(arg)
      }


      add_action_callback("文件改名") {|dialog, arg|
        文件改名("kk")
      }
      add_action_callback("清除未使用") {|dialog, arg|
        清除未使用
      }
      add_action_callback("重载ABF") {|dialog, arg|
        Sketchup::set_status_text "重载ABF"+" ing"

        path = Sketchup.find_support_file "abf_solutions/startup.rb", "Plugins"
        puts "path=" + path.to_s
        load path.to_s
        puts "重新加载ABFing……稍安勿躁……"
        Sketchup::set_status_text "重载ABF"+" 完成"
      }
      # Display the dialog box
      if RUBY_PLATFORM.index "darwin"
        show_modal
      else
        show
      end

    end
  end #AMTF窗口


end # module amtf_su
